//
//  inherihanceClasstry.hpp
//  learnC++
//
//  Created by liuzhibing on 2018/6/25.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef inherihanceClasstry_hpp
#define inherihanceClasstry_hpp

#include <stdio.h>
#include <iostream>

class A2
{
private:
    int m_x;
public:
    A2(int x) : m_x(x)
    {
        if (x <= 0)
            throw 1;
    }
};

class B2 : public A2
{
public:
    B2(int x) try : A2(x) // 注意try关键字
    {
    }
    catch (...) // note this is at same level of indentation as the function itself
    {
        // Exceptions from member initializer list or constructor body are caught here
        
        std::cerr << "Construction of A failed\n";
        
        //如果这里没有显式抛出异常，则当前异常将被隐式重新抛出
    }
        
        
    void uniquePtr(){
        
        try{
            int *john = new int(12);
            
            //智能指针出作用域后自动释放，无须delete
            std::unique_ptr<int> upJohn(john);
            
            //加入下面的代码会抛出异常
            //        ProcessPerson(john);
            
        }catch(...){
            
            std::cout << "john error";
        }
        
    }
        
};
        
/*
 try
 {
 B2 b(0);
 }
 catch (int)
 {
 std::cout << "Oops\n";
 }
 */
        
#endif /* inherihanceClasstry_hpp */
